﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ContaTelefone.Entities;
using ContaTelefone.Process;

namespace ContaTelefone
{
    public partial class frmCCUSEdit : Form
    {
        bool novo;
        CCustoEntities ccusEtt;
        CCustoProcess ccP = new CCustoProcess();

        public frmCCUSEdit(CCustoEntities pccusEtt)
        {
            InitializeComponent();
            novo = pccusEtt == null;

            if (novo)
                ccusEtt = new CCustoEntities();
            else
                ccusEtt = pccusEtt;
        }

        private void frmCCUSEdit_Load(object sender, EventArgs e)
        {
            txtCod.Text = ccusEtt.Codigo;
            txtDescr.Text = ccusEtt.Descricao;
        }

        private void btnFechar_Click(object sender, EventArgs e)
        {
            this.Close();
            this.Dispose();
        }

        private void btnSalvar_Click(object sender, EventArgs e)
        {
            if (txtCod.Text == string.Empty)
            {
                MessageBox.Show("Campo Obrigatório: 'Código'");
                return;
            }
            if (txtDescr.Text == string.Empty)
            {
                MessageBox.Show("Campo Obrigatório: 'Descrição'");
                return;
            }

            ccusEtt.Codigo = txtCod.Text;
            ccusEtt.Descricao = txtDescr.Text;

            if (novo)
                ccP.Incluir(ccusEtt);
            else
                ccP.Alterar(ccusEtt);

            btnFechar_Click(null, null);
        }

        
    }
}
